import time

from concurrent import futures
from multiprocessing import cpu_count


class Demo:
    def __init__(self, p):
        self.p = p
        print(p)
        self.init()

    def init(self):
        time.sleep(10)

    def __str__(self):
        return f"demo{self.p}"


if __name__ == '__main__':
    import gc
    start = time.time()
    with futures.ProcessPoolExecutor(max_workers=cpu_count()) as executor:
        res = executor.map(Demo, list(range(4)))
        pass
    ret = [i for i in res]
    print('before', ret)
    for i in ret:
        print(i)
        del i
    print(gc.collect())
    print('after delete', ret)
    print(time.time() - start)
